package de.flojo.game;

import java.io.*;
import java.net.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

public class ImageDrawingApplet extends JApplet{

	static String imageFileName = "AR_MARKERS_03.jpg";
	static String imagePlayFigure = "/FloJoGame/res/uboot.png";

	public ImageDrawingApplet (URL imageSrc) {

		Box bv = Box.createVerticalBox();
		add(bv);

		final ImageDrawingComponent id = new ImageDrawingComponent(imageSrc);
		
		id.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				//id.mouseDown(e);
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				//id.mouseDown(e);
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				id.mouseDown(e);
			}
		});
		
		bv.add(id);

		JSlider slider = new JSlider(0, 255);
		slider.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				JSlider slider = (JSlider)e.getSource();
				id.setValue(slider.getValue());
				
				id.state = id.STATE_CAPTURE;
				id.mapOk();
				id.repaint();
				
				//id.repaint();
				};
			});
		bv.add(slider);
		id.setValue(128);
		
		JButton buttonP = new JButton("Mein Spielfeld Generieren");

		bv.add(buttonP);
		buttonP.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				id.state = id.STATE_CAPTURE;
				id.mapOk();
				id.repaint();
			}
		});
		
		
		JButton buttonStartGame = new JButton("Spiel starten");

		bv.add(buttonStartGame);
		buttonStartGame.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				id.startGame();
			}
		});
		
	
	}

	public static void main(String s[]) throws MalformedURLException {
		
		JFrame f = new JFrame("FloJo Game");
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {System.exit(0);}
		});
		
		f.addKeyListener(new KeyListener() {
			
			@Override
			public void keyPressed(KeyEvent e) {
				System.out.println("keyPressed");
				
			}

			@Override
			public void keyReleased(KeyEvent e) {
				System.out.println("keyReleased");
				
			}

			@Override
			public void keyTyped(KeyEvent e) {
				System.out.println("keyTyped");
				
			}
		});
		
		URL imageSrc = ((new File(imageFileName)).toURI()).toURL();
		//URL imagePlayFigureSrc = ((new File(imagePlayFigure)).toURI()).toURL();
		ImageDrawingApplet id = new ImageDrawingApplet(imageSrc);

		f.add(id);
		f.pack();
		f.setVisible(true);
		f.setFocusable(true);
	}
	
}
